package com.qu.waibao.home.adpater;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.bean.Shop;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @描述 describe
 * @作者 Administrator
 * @创建时间 2018/7/23 8:59
 * @邮箱 1123599561@qq.com
 */
public class ShopAdapter extends BaseRecyclerAdapter<Shop> {
    public ShopAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new ShopViewHodler(mInflater.inflate(R.layout.shop_recycler_item,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, Shop item, int position) {
        ShopViewHodler shopViewHodler = (ShopViewHodler) holder;
        shopViewHodler.tv_buy.setTag(position);
        shopViewHodler.tv_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = (int) v.getTag();
                if(onItemBuyClickListener != null){
                    onItemBuyClickListener.onItemBuyClick(position);
                }
            }
        });
        shopViewHodler.tv_money.setText(item.getMoneysubtract());
        shopViewHodler.tv_address.setText(item.getName());
        shopViewHodler.tv_time.setText("有效期："+item.getDays()+"天");
        shopViewHodler.tv_man.setText(item.getJf());
        shopViewHodler.tv_jian.setText(item.getPrice());
    }

    class ShopViewHodler extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_buy)
        TextView tv_buy;
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.tv_address)
        TextView tv_address;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_man)
        TextView tv_man;
        @BindView(R.id.tv_jian)
        TextView tv_jian;
        public ShopViewHodler(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
    private OnItemBuyClickListener onItemBuyClickListener;
    public interface OnItemBuyClickListener{
        void onItemBuyClick(int position);
    }
    public void setOnItemBuyClickListener(OnItemBuyClickListener onItemBuyClickListener){
        this.onItemBuyClickListener = onItemBuyClickListener;
    }
}
